<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>超市订单管理系统</title>
    <link type="text/css" rel="stylesheet" href="../../static/css/style.css" th:href="@{/css/style.css}"/>
    <link type="text/css" rel="stylesheet" href="../../static/css/public.css" th:href="@{/css/public.css}"/>
    <link type="text/css" rel="stylesheet" href="../../static/css/pagination.css" th:href="@{/css/pagination.css}"/>
</head>
<body>

<!--头部-->
<div th:replace="commons/common::header"></div>
<!--时间-->
<div th:replace="commons/common::time"></div>
<!--主体内容-->
<section class="publicMian ">
    <!--left-->
    <div th:replace="commons/common::left"></div>
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>供应商管理页面</span>
            <a id="downloadExcelBtn" th:href='@{/provider/downloadExcel}' style="display: block;float: right;text-align: center;font:12px bold;">导出全部信息</a>
        </div>

        <div class="search">

            <form>
                <span>供应商编码：</span>
                <input name="proCode" id="proCode" type="text" th:value="${proCode }">

                <span>供应商名称：</span>
                <input name="proName" id="proName" type="text" th:value="${proName }">
                <input value="查 询" type="button" id="searchBtn">
                <a href="" th:href="@{/provider/add}">添加供应商</a>

            </form>

        </div>
        <!--供应商操作表格-->
        <table class="providerTable" cellpadding="0" cellspacing="0">
            <tr class="firstTr">
                <th width="10%">供应商编码</th>
                <th width="20%">供应商名称</th>
                <th width="10%">联系人</th>
                <th width="10%">联系电话</th>
                <th width="10%">传真</th>
                <th width="10%">创建时间</th>
                <th width="30%">操作</th>
            </tr>
            <tbody id="tbody"></tbody>
        </table>
        <div id="Pagination" style="text-align: center;margin-top: 30px"></div>
    </div>
</section>


<div th:replace="commons/common::footer"></div>
<script type="text/javascript" src="../../static/js/time.js" th:src="@{/js/time.js}"></script>
<script type="text/javascript" src="../../static/js/jquery-1.8.3.min.js" th:src="@{/js/jquery-1.8.3.min.js}"></script>
<script type="text/javascript" src="../../static/js/common.js" th:src="@{/js/common.js}"></script>
<script type="text/javascript" src="../../static/calendar/WdatePicker.js" th:src="@{/calendar/WdatePicker.js}"></script>
<script type="text/javascript" src="../../static/js/rollpage.js" th:src="@{/js/rollpage.js}"></script>
<script  type="text/javascript" src="../../static/js/jquery.pagination.js" th:src="@{/js/jquery.pagination.js}"></script>
<script  type="text/javascript" src="../../static/js/layer/layer.js" th:src="@{/js/layer/layer.js}"></script>
<script>
    const jsonObj = {
        pageSize: 5
    };

    function queryPage(pageIndex) {
        jsonObj.pageIndex=pageIndex+1;
        $.ajax({
            url:"[[@{/provider/dolist}]]",
            type:"post",
            beforeSend:function () {
                return true;
            },
            data:jsonObj,
            success:function (result) {
                if (result.success) {
                    const page = result.page;
                    const data=page.list;
                    let content='';
                    $.each(data,function (i,provider) {
                        content+='<tr>';
                        content+='	<td><span>'+provider.proCode+'</span></td>';
                        content+='	<td><span>'+provider.proName+'</span></td>';
                        content+='	<td><span>'+provider.proContact+'</span></td>';
                        content+='	<td><span>'+provider.proPhone+'</span></td>';
                        content+='	<td><span>'+provider.proFax+'</span></td>';
                        content+='	<td><span>'+provider.creationDate+'</span></td>';
                        content+='	<td>';
                        content+='		<span><a id="viewProvider" href="[[@{/provider/view?id=}]]'+provider.id+'" ><img src="[[@{/images/read.png}]]" alt="查看" title="查看"/></a></span>';
                        content+='		<span><a id="modifyProvider" href="[[@{/provider/modify?id=}]]'+provider.id+'"><img src="[[@{/images/xiugai.png}]]" alt="修改" title="修改"/></a></span>';
                        content+='		<span><a id="deleteProvider" onclick="deleteProvider('+provider.id+')" href="javascript:;"><img src="[[@{/images/schu.png}]]" alt="删除" title="删除"/></a></span>';
                        content+='	</td>';
                        content+='</tr>';
                    });
                    $("#tbody").html(content);
                    $("#Pagination").pagination(page.totalCount, {
                        num_edge_entries: 2,
                        num_display_entries: 4,
                        callback: queryPage,
                        items_per_page:page.pageSize,
                        current_page:(page.pageIndex-1),
                        prev_text:"上一页",
                        next_text:"下一页"
                    });
                }
            }
        })

    }

    $(function () {
        queryPage(0);
    });

    $("#searchBtn").click(function () {
        const proCode=$("#proCode").val();
        const proName=$("#proName").val();
        jsonObj.proCode=proCode;
        jsonObj.proName=proName;
        queryPage(0);
    })

    function deleteProvider(provierId){
        $.ajax({
            url:"[[@{/provider/delete}]]",
            type:"post",
            data:{
                id:provierId
            },
            beforeSend:function () {
                return true;
            },
            success:function(result){
                if (result.success){
                    window.location.href = "[[@{/provider/list}]]";
                }
            }
        })
    }

</script>
</body>
</html>